var app = angular.module('myApp',[]);

//定义controller
app.controller('myCtrl',function ($scope , $rootScope) {
	$rootScope.sky = 'gray color of the sky';
	$rootScope.commonFun = function (word) { 
		alert('Said:'+word)
	}
	$rootScope.pointitem = '1';
	$rootScope.rootpoints=[1,2,3,4,5];

	$rootScope.readRootScopeData = function () {
		alert('rootScope pointitem:'+$rootScope.pointitem)
	}

	$scope.points=[1,15,2,19,2,40];
	$scope.firstname = 'Cheng';
	$scope.lastname = 'Wang';
	$scope.data = {
		text:'hey'
	};
	$scope.ctrlData = {
		name:'lisa',
		sex:'female',
		age:'22',
	}
	$scope.selfFun = function (word) { 
		alert('Said:'+word)
	}
	$scope.self1Fun = function (word) { 
		alert('Said:'+$rootScope.color)
	}
	$scope.remove = function (index) {
		$scope.points.splice(index,1);
	}
	$rootScope.remove = function (index) {
		$rootScope.rootpoints.splice(index,1);
	}

})

//定义controller
app.controller('myCtrl1',function($scope , $rootScope) {
	$rootScope.color = 'gray';
	$scope.ctrl1Data = {
		name:'jack',
		sex:'male',
		age:'27',
	}
	$scope.pointitem = '2';
	$scope.self2Fun = function () { 
		alert('Said:'+$rootScope.sky)
	}
	$scope.commonData = $rootScope.sky;
	$rootScope.add = function () {
		$rootScope.rootpoints.push($scope.pointitem);
	}
})

//定义directive
app.directive('myDirective',function () {
	return { 
		template:"<h2>我是自定义指令:有四种方式调用自定义指令:1元素名E</h2>"
	}
});
app.directive('myDirectiveByA',function () {
	return { 
		restrict : "A",
		template:"<h2>我是自定义指令:有四种方式调用自定义指令:2属性A</h2>"
	}
});
app.directive('myDirtByC',function () {
	return {
		restrict:'C',
		template:"<h2>我是自定义指令:有四种方式调用自定义指令:3类名C</h2>"
	}
});
app.directive('myDirtByM',function () {
	return {
		restrict:'M',
        replace : true,
		template:"<h2>我是自定义指令:有四种方式调用自定义指令:4注释M</h2>"
	}
});